package com.gao.hookDemo

import org.objectweb.asm.MethodVisitor
import org.objectweb.asm.Opcodes
import org.objectweb.asm.Opcodes.*

class ClickVisitor(mv: MethodVisitor) : MethodVisitor(Opcodes.ASM6, mv) {

    override fun visitCode() {
        super.visitCode()
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitLdcInsn("this$0");
        mv.visitMethodInsn(
            INVOKESTATIC,
            "kotlin/jvm/internal/Intrinsics",
            "checkNotNullParameter",
            "(Ljava/lang/Object;Ljava/lang/String;)V",
            false
        );
        mv.visitLdcInsn("xxx");
        mv.visitLdcInsn("\u70b9\u51fb\u4e4b\u524d");
        mv.visitMethodInsn(
            INVOKESTATIC,
            "android/util/Log",
            "e",
            "(Ljava/lang/String;Ljava/lang/String;)I",
            false
        );
        mv.visitInsn(POP);
    }

    override fun visitInsn(opcode: Int) {
        mv.visitVarInsn(ASTORE, 3);
        mv.visitLdcInsn("xxx");
        mv.visitLdcInsn("\u70b9\u51fb\u4e4b\u540e");
        mv.visitMethodInsn(
            INVOKESTATIC,
            "android/util/Log",
            "e",
            "(Ljava/lang/String;Ljava/lang/String;)I",
            false
        );
        mv.visitInsn(POP);
        mv.visitInsn(RETURN);
        mv.visitMaxs(3, 4);
        mv.visitEnd();
        super.visitInsn(opcode)
    }
}
